package wxdb.parse.absyn;
import java.util.ArrayList;
import java.util.List;

import wxdb.query.*;
import wxdb.symbol.Symbol;

public class IstExp extends Exp{
	public Symbol tableName;
	public FldsExp fields;
	public ValLst values;
	
	public IstExp(int p, Symbol t, FldsExp f, ValLst v){
		pos = p;
		tableName = t;
		fields = f;
		values = v;
	}
	
	public String tableName(){
		return tableName.toString();
	}
	
	public List<Constant> vals(){
		List<Constant> vals = new ArrayList<Constant>();
		ValLst valList = values;
		Constant val;
		while(valList != null){
			if(valList.value instanceof IntVal){
				val = new IntConstant( ((IntVal)(valList.value)).ival );
				vals.add(val);
			}
			else if(valList.value instanceof StringVal){
				val = new StringConstant( ((StringVal)valList.value).sval );
				vals.add(val);
			}
			valList = valList.values;
		}
		return vals;
	}

	public List<String> fields(){
		List<String> flds = new ArrayList<String>();
		FldsExp fldsExp = fields;
		FldExp fldExp;
		while(fldsExp != null){
			fldExp = fldsExp.fldExp;
			if(fldExp instanceof NameFldExp)
				flds.add(((NameFldExp)fldExp).nameExp.fieldname.toString());
			fldsExp = fldsExp.tail;
		}
		return flds;
	}
}
